require 'rubygems'
require 'twitter'
require 'yaml'
IRCBot::Plugin.define 'tweet' do
	raise "Can't find data file" if !File.exists?($config['global']['plugin_data_dir']+'/tweet.yml')
	help_string "Tweets something to Marco's tweeter account, http://twitter.com/FaiDMarco"
	@config = YAML::load(File.open($config['global']['plugin_data_dir']+'/tweet.yml'))
	@configured = false
	def command(user,target,message,hostmask)
		if !@configured then
			Twitter::Client.configure do |conf|
				conf.user_agent = 'MarcoBot'
				conf.application_name = 'Marco'
				conf.application_version = $ircbot.version
				conf.application_url = "http://marco.niexs.net"
			end
		end
		if !message.strip.empty? and message.length <= 140 then
			client = Twitter::Client.new(:login=>@config[0],:password=>@config[1])
			client.status(:post,"#{user} says: #{message.strip}")
			privmsg(target,"Tweeted! Go to http://twitter.com/FaiDMarco to check it.")
		elsif message.length > 140
			privmsg(target,"The tweet must be smaller than 140 characters.")
		else
			privmsg(target,"I need something to tweet!")
		end
	end
end
